package com.kot.backend.controller.user.myspace;


import com.kot.backend.pojo.Post;
import com.kot.backend.pojo.User;
import com.kot.backend.service.user.myspace.UserlistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class UserlistController {

    @Autowired
    private UserlistService userlistService;

    @GetMapping("/myspace/userlist/")
    public List<User> getuserlist() {
        System.out.println("Controller start!");
        return userlistService.getuserlist();
    }

    @PostMapping("/myspace/follow/")
    public Map<String, String> follow(@RequestParam Map<String, String> map) {
        String targetId = map.get("target_id");
        return userlistService.follow(Integer.valueOf(targetId));
    }

    @PostMapping("/myspace/getuser/")
    public User getuserbyid(@RequestParam Map<String, String> map) {
        String userId = map.get("user_id");
        return userlistService.getuserbyid(Integer.valueOf(userId));
    }

    @PostMapping("/myspace/post/")
    public Map<String, String> postApost(@RequestParam Map<String, String> map) {
        String content = map.get("content");
        return userlistService.postApost(content);
    }

    @PostMapping("/myspace/getpost/")
    public List<Post> getpostbyid(@RequestParam Map<String, String> map) {
        String userId = map.get("user_id");
        return userlistService.getpostbyid(Integer.valueOf(userId));
    }

    @DeleteMapping("/myspace/post/")
    public Map<String, String> deleteApost(@RequestParam Map<String, String> map) {
        String postId = map.get("post_id");
        return userlistService.deleteApost(Integer.valueOf(postId));
    }

    @GetMapping("/myspace/getpostall/")
    public List<Post> getpostall() {
        return userlistService.getpostall();
    }

}
